import random

from common.base_page import BasePage
from locator.Index_Locator import Index_Locator as IL


class Index_page(BasePage):

    def is_login_success(self):
        try:
            self.get_element(IL.loc_login_success, "查看头像")
        except:
            return False
        else:
            return True

    # 创建课程
    def add_class(self):
        self.get_click(IL.add_or_join_class, "点击创建或加入")
        self.get_click(IL.add_class, "点击创建课程")
        self.input_text(IL.input_class_name, "课程{}".format(random.randint(0, 100)), "输入课程")
        self.get_click(IL.btu_creat_class, "点击创建")

    # 加入课程
    def join_class(self, code):

        self.get_click(IL.join_class, "点击加入课程")
        self.input_text(IL.input_class_code, code, "输入课程号")
        self.get_click(IL.btu_join_class, "点击加入")

    # 加入课程错误等待错误消息
    def error_join(self):
        return self.get_element_text(IL.error_class_text, "添加课程错误")

    # 错误等待
    def wait_see(self):
        self.wait_element_see(IL.error_class_text, "等待显示")

    # # 判断加入成功
    # def join_is_success(self):
    #     loc =